/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utility.com.treeTable;


import java.awt.Dimension;
import javax.swing.JTable;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreeModel;

/**
 *
 * @author Yusup Jauhari Shandi <in.visi>
 */
public class TreeTable extends JTable{
    private TreeTableCellRenderer tree;
    private TreeSelectionListener treeSelectionListener; 
    private TreeModel treeModel; 
    public TreeTable(AbstractTreeTableModel treeTableModel) {
        super();
 
        // JTree erstellen.
        treeModel = treeTableModel;
        tree = new TreeTableCellRenderer(this, treeModel);
         
        // Modell setzen.
        super.setModel(new TreeTableModelAdapter(treeTableModel, tree));
         
        // Gleichzeitiges Selektieren fuer Tree und Table.
        TreeTableSelectionModel selectedModel = new TreeTableSelectionModel();
        tree.setSelectionModel(selectedModel); //For the tree
        setSelectionModel(selectedModel.getListSelectionModel()); //For the table
 
         
        // Renderer fuer den Tree.
        setDefaultRenderer(TreeTableModel.class, tree);
        // Editor fuer die TreeTable
        setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor(tree, this));
         
        // Kein Grid anzeigen.
        setShowGrid(false);
 
        // Keine Abstaende.
        setIntercellSpacing(new Dimension(0, 0));
 
        
    }
    
    public void setModel(AbstractTreeTableModel treeTableModel){
        tree = new TreeTableCellRenderer(this, treeTableModel);
         
        // Modell setzen.
        super.setModel(new TreeTableModelAdapter(treeTableModel, tree));
    }
    
    public void setTreeSelectionListener(TreeSelectionListener treeSelectionListener) {
        this.treeSelectionListener = treeSelectionListener;
        tree.addTreeSelectionListener(treeSelectionListener);
    }

    public TreeTableCellRenderer getTree() {
        return tree;
    }

    public TreeModel getTreeModel() {
        return treeModel;
    }
    
    
    
}
